package cn.bonoon.entities;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import cn.bonoon.kernel.support.entities.AbstractPersistable;

/**
 * 被文件的明细
 * @author jackson
 *
 */
@MappedSuperclass
public abstract class AbstractRawdataImportItem extends AbstractPersistable{
	
	private static final long serialVersionUID = -1625809489188687901L;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "R_SUBJECT_ID")
	private RawdataImportEntity subject;
	
	/** 不一定有值，只有这些记录是异常或用户选择导出这条记录的，则会有导出的对象 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "R_EXPORT_ID")
	private RawdataExportEntity export;
	
	@Enumerated
	@Column(name = "C_STATUS")
	private RawdataImportItemStatus status = RawdataImportItemStatus.NONE;
	
	@Column(name = "C_REMARK", length = 1024)
	private String remark;
	
	/** 这条导入记录的处理结果 */
	@Enumerated
	@Column(name = "C_TREATMENT")
	private RawdataItemTreatmentStatus treatment = RawdataItemTreatmentStatus.NONE;
	/** 导入记录的最后处理时间 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "C_TREATAT")
	private Date treatAt;
	
//	public boolean error(){
//		return false;
//	}
	
	public RawdataImportEntity getSubject() {
		return subject;
	}
	public void setSubject(RawdataImportEntity subject) {
		this.subject = subject;
	}
	public RawdataExportEntity getExport() {
		return export;
	}
	public void setExport(RawdataExportEntity export) {
		this.export = export;
	}
	public RawdataImportItemStatus getStatus() {
		return status;
	}
	public void setStatus(RawdataImportItemStatus status) {
		this.status = status;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public RawdataItemTreatmentStatus getTreatment() {
		return treatment;
	}
	public void setTreatment(RawdataItemTreatmentStatus treatment) {
		this.treatment = treatment;
	}
	public Date getTreatAt() {
		return treatAt;
	}
	public void setTreatAt(Date treatAt) {
		this.treatAt = treatAt;
	}

	/** 设置为异常 */
	public void abnormal(String message) {
		if(null == remark) remark = message;
		else remark += "," + message;
		
		status = RawdataImportItemStatus.ABNORMAL;
	}
	
}
